< previous page page_497 next page >

Page 497
e10a6a0a59f035e870d90cca05b85fce.gif
    imid = (i1 + i2) \ 2
    jmid = (j1 + j2) \ 2
    points(i1, jmid).coord(2) = _
        (y11 + y12) / 2 + 2 * Dy * Rnd - Dy
    points(i2,  jmid).coord(2)  = _
        (y21 + y22) / 2 + 2 * Dy * Rnd - Dy
    points(imid, j1).coord(2) = _
        (y11 + y21) / 2 + 2 * Dy * Rnd - Dy
    points(imid, j2).coord(2) = _
        (y12 + y22) / 2 + 2 * Dy * Rnd - Dy
    points(imid, jmid).coord(2) = _
        (y11 + y12 + y21 + y22) / 4 + 2 * Dy * Rnd - Dy

    ' Recursively subdivide the four new areas.
    Subdivide i1, imid, j1, jmid, Dy / 2
    Subdivide imid, i2, j1, jmid, Dy / 2
    Subdivide i1, imid, jmid, j2, Dy / 2
    Subdivide imid, i2, jmid, j2, Dy / 2
End Sub
Example program Fractal demonstrates the FractalGrid3d class. Use the option buttons to select a basic surface type. The program generates a rough grid to guide the development of the surface pseudo-randomly. It then uses the GenerateSurface subroutine to refine the grid. Click on the picture box and use the arrow keys to change the viewing direction.
Enter the level of recursion and the maximum amount of random change allowed in the text boxes. If you set the level of recursion to 0, the program displays a basic pseudo-random grid surface that has not been modified by the GenerateSurface routine. As you set the level of recursion to higher values, the program creates more refined surfaces. Be careful not to set the level of recursion too high until you know how long the program takes on your computer.
Example program Altitude uses similar techniques to display a colored surface. It creates a pseudo-random surface and displays it using the Z-Order algorithm much as program Fractal does. Before it fills each area, however, this program sets its fill color to a value that depends on the area's Y value. The colors are chosen from a smooth gradient with green for the smallest Y values and red for the largest. This display makes it easier to see the highest and lowest points on the surface.
Example program Valley, shown in Figure 14.20, uses similar code to create a moderately realistic valley scene. It begins with a pseudo-random valley shape and then makes some specialized adjustments. First it flattens the valley floor and carves a riverbed in it. It then displays the surface using the ZOrder algorithm but it colors the areas specially. It makes the low areas in the riverbed blue and it makes the highest areas white to simulate snow. The program colors steep areas gray to represent rock cliffs. It colors the remaining areas green, using different shades of green for different altitudes.

 
< previous page page_497 next page >